home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / gnumake.zip / READ.C < prev    next >
C/C++ Source or Header  |  1994-06-07  |  57KB  |  2,058 lines

  1. /* Reading and parsing of makefiles for GNU Make.
  2. Copyright (C) 1988, 89, 90, 91, 92, 93, 94 Free Software Foundation, Inc.
  3. This file is part of GNU Make.
  4.  
  5. GNU Make is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. GNU Make is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU Make; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "make.h"
  20. #include "commands.h"
  21. #include "dep.h"
  22. #include "file.h"
  23. #include "variable.h"
  24.  
  25. /* This is POSIX.2, but most systems using -DPOSIX probably don't have it.  */
  26. #ifdef    HAVE_GLOB_H
  27. #include <glob.h>
  28. #else
  29. #include "glob/glob.h"
  30. #endif
  31.  
  32. #include <pwd.h>
  33. struct passwd *getpwnam ();
  34.  
  35.  
  36. static int read_makefile ();
  37. static unsigned int readline (), do_define ();
  38. static int conditional_line ();
  39. static void record_files ();
  40. static char *find_semicolon ();
  41.  
  42.  
  43. /* A `struct linebuffer' is a structure which holds a line of text.
  44.    `readline' reads a line from a stream into a linebuffer
  45.    and works regardless of the length of the line.  */
  46.  
  47. struct linebuffer
  48.   {
  49.     /* Note:  This is the number of bytes malloc'ed for `buffer'
  50.        It does not indicate `buffer's real length.
  51.        Instead, a null char indicates end-of-string.  */
  52.     unsigned int size;
  53.     char *buffer;
  54.   };
  55.  
  56. #define initbuffer(lb) (lb)->buffer = (char *) xmalloc ((lb)->size = 200)
  57. #define freebuffer(lb) free ((lb)->buffer)
  58.  
  59.  
  60. /* A `struct conditionals' contains the information describing
  61.    all the active conditionals in a makefile.
  62.  
  63.    The global variable `conditionals' contains the conditionals
  64.    information for the current makefile.  It is initialized from
  65.    the static structure `toplevel_conditionals' and is later changed
  66.    to new structures for included makefiles.  */
  67.  
  68. struct conditionals
  69.   {
  70.     unsigned int if_cmds;    /* Depth of conditional nesting.  */
  71.     unsigned int allocated;    /* Elts allocated in following arrays.  */
  72.     char *ignoring;        /* Are we ignoring or interepreting?  */
  73.     char *seen_else;        /* Have we already seen an `else'?  */
  74.   };
  75.  
  76. static struct conditionals toplevel_conditionals;
  77. static struct conditionals *conditionals = &toplevel_conditionals;
  78.   
  79.  
  80. /* Default directories to search for include files in  */
  81.  
  82. static char *default_include_directories[] =
  83.   {
  84.     INCLUDEDIR,
  85.     "/usr/gnu/include",
  86.     "/usr/local/include",
  87.     "/usr/include",
  88.     0
  89.   };
  90.  
  91. /* List of directories to search for include files in  */
  92.  
  93. static char **include_directories;
  94.  
  95. /* Maximum length of an element of the above.  */
  96.  
  97. static unsigned int max_incl_len;
  98.  
  99. /* The filename and pointer to line number of the
  100.    makefile currently being read in.  */
  101.  
  102. char *reading_filename;
  103. unsigned int *reading_lineno_ptr;
  104.  
  105. /* The chain of makefiles read by read_makefile.  */
  106.  
  107. static struct dep *read_makefiles = 0;
  108.  
  109. /* Read in all the makefiles and return the chain of their names.  */
  110.  
  111. struct dep *
  112. read_all_makefiles (makefiles)
  113.      char **makefiles;
  114. {
  115.   unsigned int num_makefiles = 0;
  116.  
  117.   if (debug_flag)
  118.     puts ("Reading makefiles...");
  119.  
  120.   /* If there's a non-null variable MAKEFILES, its value is a list of
  121.      files to read first thing.  But don't let it prevent reading the
  122.      default makefiles and don't let the default goal come from there.  */
  123.  
  124.   {
  125.     char *value;
  126.     char *name, *p;
  127.     unsigned int length;
  128.  
  129.     {
  130.       /* Turn off --warn-undefined-variables while we expand MAKEFILES.  */
  131.       int save = warn_undefined_variables_flag;
  132.       warn_undefined_variables_flag = 0;
  133.  
  134.       value = allocated_variable_expand ("$(MAKEFILES)");
  135.  
  136.       warn_undefined_variables_flag = save;
  137.     }
  138.  
  139.     /* Set NAME to the start of next token and LENGTH to its length.
  140.        MAKEFILES is updated for finding remaining tokens.  */
  141.     p = value;
  142.     while ((name = find_next_token (&p, &length)) != 0)
  143.       {
  144.     if (*p != '\0')
  145.       *p++ = '\0';
  146.     (void) read_makefile (name,
  147.                   RM_NO_DEFAULT_GOAL | RM_INCLUDED | RM_DONTCARE);
  148.       }
  149.  
  150.     free (value);
  151.   }
  152.  
  153.   /* Read makefiles specified with -f switches.  */
  154.  
  155.   if (makefiles != 0)
  156.     while (*makefiles != 0)
  157.       {
  158.     struct dep *tail = read_makefiles;
  159.     register struct dep *d;
  160.  
  161.     if (! read_makefile (*makefiles, 0))
  162.       perror_with_name ("", *makefiles);
  163.  
  164.     /* Find the right element of read_makefiles.  */
  165.     d = read_makefiles;
  166.     while (d->next != tail)
  167.       d = d->next;
  168.  
  169.     /* Use the storage read_makefile allocates.  */
  170.     *makefiles = dep_name (d);
  171.     ++num_makefiles;
  172.     ++makefiles;
  173.       }
  174.  
  175.   /* If there were no -f switches, try the default names.  */
  176.  
  177.   if (num_makefiles == 0)
  178.     {
  179.       static char *default_makefiles[] =
  180.     { "GNUmakefile", "makefile", "Makefile", 0 };
  181.       register char **p = default_makefiles;
  182.       while (*p != 0 && !file_exists_p (*p))
  183.     ++p;
  184.  
  185.       if (*p != 0)
  186.     {
  187.       if (! read_makefile (*p, 0))
  188.         perror_with_name ("", *p);
  189.     }
  190.       else
  191.     {
  192.       /* No default makefile was found.  Add the default makefiles to the
  193.          `read_makefiles' chain so they will be updated if possible.  */
  194.       struct dep *tail = read_makefiles;
  195.       for (p = default_makefiles; *p != 0; ++p)
  196.         {
  197.           struct dep *d = (struct dep *) xmalloc (sizeof (struct dep));
  198.           d->name = 0;
  199.           d->file = enter_file (*p);
  200.           d->file->dontcare = 1;
  201.           /* Tell update_goal_chain to bail out as soon as this file is
  202.          made, and main not to die if we can't make this file.  */
  203.           d->changed = RM_DONTCARE;
  204.           if (tail == 0)
  205.         read_makefiles = d;
  206.           else
  207.         tail->next = d;
  208.           tail = d;
  209.         }
  210.       if (tail != 0)
  211.         tail->next = 0;
  212.     }
  213.     }
  214.  
  215.   return read_makefiles;
  216. }
  217.  
  218. /* Read file FILENAME as a makefile and add its contents to the data base.
  219.  
  220.    FLAGS contains bits as above.
  221.  
  222.    FILENAME is added to the `read_makefiles' chain.
  223.  
  224.    Returns 1 if a file was found and read, 0 if not.  */
  225.  
  226. static int
  227. read_makefile (filename, flags)
  228.      char *filename;
  229.      int flags;
  230. {
  231.   static char *collapsed = 0;
  232.   static unsigned int collapsed_length = 0;
  233.   register FILE *infile;
  234.   struct linebuffer lb;
  235.   unsigned int commands_len = 200;
  236.   char *commands = (char *) xmalloc (200);
  237.   unsigned int commands_idx = 0;
  238.   unsigned int commands_started;
  239.   register char *p;
  240.   char *p2;
  241.   int ignoring = 0, in_ignored_define = 0;
  242.   int no_targets = 0;        /* Set when reading a rule without targets.  */
  243.  
  244.   struct nameseq *filenames = 0;
  245.   struct dep *deps;
  246.   unsigned int lineno = 1;
  247.   unsigned int nlines = 0;
  248.   int two_colon;
  249.   char *pattern = 0, *pattern_percent;
  250.  
  251.   int makefile_errno;
  252.  
  253. #define record_waiting_files()                              \
  254.   do                                          \
  255.     {                                           \
  256.       if (filenames != 0)                              \
  257.     record_files (filenames, pattern, pattern_percent, deps,          \
  258.               commands_started, commands, commands_idx,              \
  259.               two_colon, filename, lineno,                  \
  260.               !(flags & RM_NO_DEFAULT_GOAL));                       \
  261.       filenames = 0;                                  \
  262.       commands_idx = 0;                                  \
  263.       pattern = 0;                                  \
  264.     } while (0)
  265.  
  266. #ifdef    lint    /* Suppress `used before set' messages.  */
  267.   two_colon = 0;
  268. #endif
  269.  
  270.   if (debug_flag)
  271.     {
  272.       printf ("Reading makefile `%s'", filename);
  273.       if (flags & RM_NO_DEFAULT_GOAL)
  274.     printf (" (no default goal)");
  275.       if (flags & RM_INCLUDED)
  276.     printf (" (search path)");
  277.       if (flags & RM_DONTCARE)
  278.     printf (" (don't care)");
  279.       if (flags & RM_NO_TILDE)
  280.     printf (" (no ~ expansion)");
  281.       puts ("...");
  282.     }
  283.  
  284.   /* First, get a stream to read.  */
  285.  
  286.   /* Expand ~ in FILENAME unless it came from `include',
  287.      in which case it was already done.  */
  288.   if (!(flags & RM_NO_TILDE) && filename[0] == '~')
  289.     {
  290.       char *expanded = tilde_expand (filename);
  291.       /* This is a possible memory leak, but I don't care.  */
  292.       if (expanded != 0)
  293.     filename = expanded;
  294.     }
  295.  
  296.   infile = fopen (filename, "r");
  297.   /* Save the error code so we print the right message later.  */
  298.   makefile_errno = errno;
  299.  
  300.   /* If the makefile wasn't found and it's either a makefile from
  301.      the `MAKEFILES' variable or an included makefile,
  302.      search the included makefile search path for this makefile.  */
  303.  
  304.   if (infile == 0 && (flags & RM_INCLUDED) && *filename != '/')
  305.     {
  306.       register unsigned int i;
  307.       for (i = 0; include_directories[i] != 0; ++i)
  308.     {
  309.       char *name = concat (include_directories[i], "/", filename);
  310.       infile = fopen (name, "r");
  311.       if (infile == 0)
  312.         free (name);
  313.       else
  314.         {
  315.           filename = name;
  316.           break;
  317.         }
  318.     }
  319.     }
  320.  
  321.   /* Add FILENAME to the chain of read makefiles.  */
  322.   deps = (struct dep *) xmalloc (sizeof (struct dep));
  323.   deps->next = read_makefiles;
  324.   read_makefiles = deps;
  325.   deps->name = 0;
  326.   deps->file = lookup_file (filename);
  327.   if (deps->file == 0)
  328.     {
  329.       deps->file = enter_file (savestring (filename, strlen (filename)));
  330.       if (flags & RM_DONTCARE)
  331.     deps->file->dontcare = 1;
  332.     }
  333.   filename = deps->file->name;
  334.   deps->changed = flags;
  335.   deps = 0;
  336.  
  337.   /* If the makefile can't be found at all, give up entirely.  */
  338.  
  339.   if (infile == 0)
  340.     {
  341.       /* If we did some searching, errno has the error from the last
  342.      attempt, rather from FILENAME itself.  Restore it in case the
  343.      caller wants to use it in a message.  */
  344.       errno = makefile_errno;
  345.       return 0;
  346.     }
  347.  
  348.   reading_filename = filename;
  349.   reading_lineno_ptr = &lineno;
  350.  
  351.   /* Loop over lines in the file.
  352.      The strategy is to accumulate target names in FILENAMES, dependencies
  353.      in DEPS and commands in COMMANDS.  These are used to define a rule
  354.      when the start of the next rule (or eof) is encountered.  */
  355.  
  356.   initbuffer (&lb);
  357.  
  358.   while (!feof (infile))
  359.     {
  360.       lineno += nlines;
  361.       nlines = readline (&lb, infile, filename, lineno);
  362.  
  363.       if (collapsed_length < lb.size)
  364.     {
  365.       collapsed_length = lb.size;
  366.       if (collapsed != 0)
  367.         free (collapsed);
  368.       collapsed = (char *) xmalloc (collapsed_length);
  369.     }
  370.       strcpy (collapsed, lb.buffer);
  371.       /* Collapse continuation lines.  */
  372.       collapse_continuations (collapsed);
  373.       remove_comments (collapsed);
  374.  
  375.       p = collapsed;
  376.       while (isspace (*p) && *p != '\t')
  377.     ++p;
  378.       /* We cannot consider a line containing just a tab to be empty
  379.      because it might constitute an empty command for a target.  */
  380.       if (*p == '\0' && lb.buffer[0] != '\t')
  381.     continue;
  382.  
  383.       /* strncmp is first to avoid dereferencing out into space.  */
  384. #define    word1eq(s, l)     (!strncmp (s, p, l) \
  385.              && (p[l] == '\0' || isblank (p[l])))
  386.       if (!in_ignored_define
  387.       && (word1eq ("ifdef", 5) || word1eq ("ifndef", 6)
  388.           || word1eq ("ifeq", 4) || word1eq ("ifneq", 5)
  389.           || word1eq ("else", 4) || word1eq ("endif", 5)))
  390.     {
  391.       int i = conditional_line (p, filename, lineno);
  392.       if (i >= 0)
  393.         ignoring = i;
  394.       else
  395.         makefile_fatal (filename, lineno,
  396.                 "invalid syntax in conditional");
  397.       continue;
  398.     }
  399.       else if (word1eq ("endef", 5))
  400.     {
  401.       if (in_ignored_define)
  402.         in_ignored_define = 0;
  403.       else
  404.         makefile_fatal (filename, lineno, "extraneous `endef'");
  405.       continue;
  406.     }
  407.       else if (word1eq ("define", 6))
  408.     {
  409.       if (ignoring)
  410.         in_ignored_define = 1;
  411.       else
  412.         {
  413.           p2 = next_token (p + 6);
  414.           /* Let the variable name be the whole rest of the line,
  415.          with trailing blanks stripped (comments have already been
  416.          removed), so it could be a complex variable/function
  417.          reference that might contain blanks.  */
  418.           p = index (p2, '\0');
  419.           while (isblank (p[-1]))
  420.         --p;
  421.           lineno = do_define (p2, p - p2, o_file,
  422.                   lineno, infile, filename);
  423.         }
  424.       continue;
  425.     }
  426.       else if (word1eq ("override", 8))
  427.     {
  428.       p2 = next_token (p + 8);
  429.       if (p2 == 0)
  430.         makefile_error (filename, lineno, "empty `override' directive");
  431.       if (!strncmp (p2, "define", 6) && (isblank (p2[6]) || p2[6] == '\0'))
  432.         {
  433.           if (ignoring)
  434.         in_ignored_define = 1;
  435.           else
  436.         {
  437.           p2 = next_token (p2 + 6);
  438.           /* Let the variable name be the whole rest of the line,
  439.              with trailing blanks stripped (comments have already been
  440.              removed), so it could be a complex variable/function
  441.              reference that might contain blanks.  */
  442.           p = index (p2, '\0');
  443.           while (isblank (p[-1]))
  444.             --p;
  445.           lineno = do_define (p2, p - p2, o_override,
  446.                       lineno, infile, filename);
  447.         }
  448.         }
  449.       else if (!ignoring
  450.            && !try_variable_definition (filename, lineno,
  451.                         p2, o_override))
  452.         makefile_error (filename, lineno, "empty `override' directive");
  453.  
  454.       continue;
  455.     }
  456.  
  457.       if (ignoring)
  458.     /* Ignore the line.  We continue here so conditionals
  459.        can appear in the middle of a rule.  */
  460.     continue;
  461.       else if (lb.buffer[0] == '\t')
  462.     {
  463.       /* This line is a shell command.  */
  464.       unsigned int len;
  465.  
  466.       if (no_targets)
  467.         /* Ignore the commands in a rule with no targets.  */
  468.         continue;
  469.  
  470.       /* If there is no preceding rule line, don't treat this line
  471.          as a command, even though it begins with a tab character.
  472.          SunOS 4 make appears to behave this way.  */
  473.  
  474.       if (filenames != 0)
  475.         {
  476.           /* Append this command line to the line being accumulated.  */
  477.           p = lb.buffer;
  478.           if (commands_idx == 0)
  479.         commands_started = lineno;
  480.           len = strlen (p);
  481.           if (len + 1 + commands_idx > commands_len)
  482.         {
  483.           commands_len = (len + 1 + commands_idx) * 2;
  484.           commands = (char *) xrealloc (commands, commands_len);
  485.         }
  486.           bcopy (p, &commands[commands_idx], len);
  487.           commands_idx += len;
  488.           commands[commands_idx++] = '\n';
  489.  
  490.           continue;
  491.         }
  492.     }
  493.  
  494.       if (word1eq ("export", 6))
  495.     {
  496.       struct variable *v;
  497.       p2 = next_token (p + 6);
  498.       if (*p2 == '\0')
  499.         export_all_variables = 1;
  500.       v = try_variable_definition (filename, lineno, p2, o_file);
  501.       if (v != 0)
  502.         v->export = v_export;
  503.       else
  504.         {
  505.           unsigned int len;
  506.           for (p = find_next_token (&p2, &len); p != 0;
  507.            p = find_next_token (&p2, &len))
  508.         {
  509.           v = lookup_variable (p, len);
  510.           if (v == 0)
  511.             v = define_variable (p, len, "", o_file, 0);
  512.           v->export = v_export;
  513.         }
  514.         }
  515.     }
  516.       else if (word1eq ("unexport", 8))
  517.     {
  518.       unsigned int len;
  519.       struct variable *v;
  520.       p2 = next_token (p + 8);
  521.       if (*p2 == '\0')
  522.         export_all_variables = 0;
  523.       for (p = find_next_token (&p2, &len); p != 0;
  524.            p = find_next_token (&p2, &len))
  525.         {
  526.           v = lookup_variable (p, len);
  527.           if (v == 0)
  528.         v = define_variable (p, len, "", o_file, 0);
  529.           v->export = v_noexport;
  530.         }
  531.     }
  532.       else if (word1eq ("include", 7) || word1eq ("-include", 8))
  533.     {
  534.       /* We have found an `include' line specifying a nested
  535.          makefile to be read at this point.  */
  536.       struct conditionals *save, new_conditionals;
  537.       struct nameseq *files;
  538.       /* "-include" (vs "include") says no
  539.          error if the file does not exist.  */
  540.       int noerror = p[0] == '-';
  541.  
  542.       p = allocated_variable_expand (next_token (p + (noerror ? 9 : 8)));
  543.       if (*p == '\0')
  544.         {
  545.           makefile_error (filename, lineno,
  546.                   "no file name for `%sinclude'",
  547.                   noerror ? "-" : "");
  548.           continue;
  549.         }
  550.  
  551.       /* Parse the list of file names.  */
  552.       p2 = p;
  553.       files = multi_glob (parse_file_seq (&p2, '\0',
  554.                           sizeof (struct nameseq),
  555.                           1),
  556.                   sizeof (struct nameseq));
  557.       free (p);
  558.  
  559.       /* Save the state of conditionals and start
  560.          the included makefile with a clean slate.  */
  561.       save = conditionals;
  562.       bzero ((char *) &new_conditionals, sizeof new_conditionals);
  563.       conditionals = &new_conditionals;
  564.  
  565.       /* Record the rules that are waiting so they will determine
  566.          the default goal before those in the included makefile.  */
  567.       record_waiting_files ();
  568.  
  569.       /* Read each included makefile.  */
  570.       while (files != 0)
  571.         {
  572.           struct nameseq *next = files->next;
  573.           char *name = files->name;
  574.           free (files);
  575.           files = next;
  576.  
  577.           if (! read_makefile (name, (RM_INCLUDED | RM_NO_TILDE
  578.                       | (noerror ? RM_DONTCARE : 0)))
  579.           && ! noerror)
  580.         makefile_error (filename, lineno,
  581.                 "%s: %s", name, strerror (errno));
  582.         }
  583.  
  584.       /* Free any space allocated by conditional_line.  */
  585.       if (conditionals->ignoring)
  586.         free (conditionals->ignoring);
  587.       if (conditionals->seen_else)
  588.         free (conditionals->seen_else);
  589.  
  590.       /* Restore state.  */
  591.       conditionals = save;
  592.       reading_filename = filename;
  593.       reading_lineno_ptr = &lineno;
  594.     }
  595.       else if (word1eq ("vpath", 5))
  596.     {
  597.       char *pattern;
  598.       unsigned int len;
  599.       p2 = variable_expand (p + 5);
  600.       p = find_next_token (&p2, &len);
  601.       if (p != 0)
  602.         {
  603.           pattern = savestring (p, len);
  604.           p = find_next_token (&p2, &len);
  605.           /* No searchpath means remove all previous
  606.          selective VPATH's with the same pattern.  */
  607.         }
  608.       else
  609.         /* No pattern means remove all previous selective VPATH's.  */
  610.         pattern = 0;
  611.       construct_vpath_list (pattern, p);
  612.       if (pattern != 0)
  613.         free (pattern);
  614.     }
  615. #undef    word1eq
  616.       else if (try_variable_definition (filename, lineno, p, o_file))
  617.     /* This line has been dealt with.  */
  618.     ;
  619.       else if (lb.buffer[0] == '\t')
  620.     {
  621.       p = lb.buffer;
  622.       while (isblank (*p))
  623.         ++p;
  624.       if (*p == '\0')
  625.         /* The line is completely blank; that is harmless.  */
  626.         continue;
  627.       /* This line starts with a tab but was not caught above
  628.          because there was no preceding target, and the line
  629.          might have been usable as a variable definition.
  630.          But now it is definitely lossage.  */
  631.       makefile_fatal (filename, lineno,
  632.               "commands commence before first target");
  633.     }
  634.       else
  635.     {
  636.       /* This line describes some target files.  */
  637.  
  638.       char *cmdleft;
  639.  
  640.       /* Record the previous rule.  */
  641.  
  642.       record_waiting_files ();
  643.  
  644.       /* Look for a semicolon in the unexpanded line.  */
  645.       cmdleft = find_semicolon (lb.buffer);
  646.       if (cmdleft != 0)
  647.         /* Found one.  Cut the line short there before expanding it.  */
  648.         *cmdleft = '\0';
  649.  
  650.       collapse_continuations (lb.buffer);
  651.  
  652.       /* Expand variable and function references before doing anything
  653.          else so that special characters can be inside variables.  */
  654.       p = variable_expand (lb.buffer);
  655.  
  656.       if (cmdleft == 0)
  657.         /* Look for a semicolon in the expanded line.  */
  658.         cmdleft = find_semicolon (p);
  659.  
  660.       if (cmdleft != 0)
  661.         /* Cut the line short at the semicolon.  */
  662.         *cmdleft = '\0';
  663.  
  664.       /* Remove comments from the line.  */
  665.       remove_comments (p);
  666.  
  667.       p2 = next_token (p);
  668.       if (*p2 == '\0')
  669.         {
  670.           if (cmdleft != 0)
  671.         makefile_fatal (filename, lineno,
  672.                 "missing rule before commands");
  673.           else
  674.         /* This line contained a variable reference that
  675.            expanded to nothing but whitespace.  */
  676.         continue;
  677.         }
  678.       else if (*p2 == ':')
  679.         {
  680.           /* We accept and ignore rules without targets for
  681.          compatibility with SunOS 4 make.  */
  682.           no_targets = 1;
  683.           continue;
  684.         }
  685.  
  686.       filenames = multi_glob (parse_file_seq (&p2, ':',
  687.                           sizeof (struct nameseq),
  688.                           1),
  689.                   sizeof (struct nameseq));
  690.       if (*p2++ == '\0')
  691.         makefile_fatal (filename, lineno, "missing separator");
  692.       /* Is this a one-colon or two-colon entry?  */
  693.       two_colon = *p2 == ':';
  694.       if (two_colon)
  695.         p2++;
  696.  
  697.       /* We have some targets, so don't ignore the following commands.  */
  698.       no_targets = 0;
  699.  
  700.       /* Is this a static pattern rule: `target: %targ: %dep; ...'?  */
  701.       p = index (p2, ':');
  702. #ifdef __EMX__
  703.       /* allow path names with drive specifications (x:) */
  704.       if (p != 0 && !isspace(p[1]))
  705.         p = 0;
  706. #endif
  707.       while (p != 0 && p[-1] == '\\')
  708.         {
  709.           register char *q = &p[-1];
  710.           register int backslash = 0;
  711.           while (*q-- == '\\')
  712.         backslash = !backslash;
  713.           if (backslash)
  714.         p = index (p + 1, ':');
  715.           else
  716.         break;
  717.         }
  718.       if (p != 0)
  719.         {
  720.           struct nameseq *target;
  721.           target = parse_file_seq (&p2, ':', sizeof (struct nameseq), 1);
  722.           ++p2;
  723.           if (target == 0)
  724.         makefile_fatal (filename, lineno, "missing target pattern");
  725.           else if (target->next != 0)
  726.         makefile_fatal (filename, lineno, "multiple target patterns");
  727.           pattern = target->name;
  728.           pattern_percent = find_percent (pattern);
  729.           if (pattern_percent == 0)
  730.         makefile_fatal (filename, lineno,
  731.                 "target pattern contains no `%%'");
  732.         }
  733.       else
  734.         pattern = 0;
  735.  
  736.       /* Parse the dependencies.  */
  737.       deps = (struct dep *)
  738.         multi_glob (parse_file_seq (&p2, '\0', sizeof (struct dep), 1),
  739.             sizeof (struct dep));
  740.  
  741.       commands_idx = 0;
  742.       if (cmdleft != 0)
  743.         {
  744.           /* Semicolon means rest of line is a command.  */
  745.           unsigned int len = strlen (cmdleft + 1);
  746.  
  747.           commands_started = lineno;
  748.  
  749.           /* Add this command line to the buffer.  */
  750.           if (len + 2 > commands_len)
  751.         {
  752.           commands_len = (len + 2) * 2;
  753.           commands = (char *) xrealloc (commands, commands_len);
  754.         }
  755.           bcopy (cmdleft + 1, commands, len);
  756.           commands_idx += len;
  757.           commands[commands_idx++] = '\n';
  758.         }
  759.  
  760.       continue;
  761.     }
  762.  
  763.       /* We get here except in the case that we just read a rule line.
  764.      Record now the last rule we read, so following spurious
  765.      commands are properly diagnosed.  */
  766.       record_waiting_files ();
  767.       no_targets = 0;
  768.     }
  769.  
  770.   if (conditionals->if_cmds)
  771.     makefile_fatal (filename, lineno, "missing `endif'");
  772.  
  773.   /* At eof, record the last rule.  */
  774.   record_waiting_files ();
  775.  
  776.   freebuffer (&lb);
  777.   free ((char *) commands);
  778.   fclose (infile);
  779.  
  780.   reading_filename = 0;
  781.   reading_lineno_ptr = 0;
  782.  
  783.   return 1;
  784. }
  785.  
  786. /* Execute a `define' directive.
  787.    The first line has already been read, and NAME is the name of
  788.    the variable to be defined.  The following lines remain to be read.
  789.    LINENO, INFILE and FILENAME refer to the makefile being read.
  790.    The value returned is LINENO, updated for lines read here.  */
  791.  
  792. static unsigned int
  793. do_define (name, namelen, origin, lineno, infile, filename)
  794.      char *name;
  795.      unsigned int namelen;
  796.      enum variable_origin origin;
  797.      unsigned int lineno;
  798.      FILE *infile;
  799.      char *filename;
  800. {
  801.   struct linebuffer lb;
  802.   unsigned int nlines = 0;
  803.   unsigned int length = 100;
  804.   char *definition = (char *) xmalloc (100);
  805.   register unsigned int idx = 0;
  806.   register char *p;
  807.  
  808.   /* Expand the variable name.  */
  809.   char *var = (char *) alloca (namelen + 1);
  810.   bcopy (name, var, namelen);
  811.   var[namelen] = '\0';
  812.   var = variable_expand (var);
  813.  
  814.   initbuffer (&lb);
  815.   while (!feof (infile))
  816.     {
  817.       lineno += nlines;
  818.       nlines = readline (&lb, infile, filename, lineno);
  819.  
  820.       collapse_continuations (lb.buffer);
  821.  
  822.       p = next_token (lb.buffer);
  823.       if ((p[5] == '\0' || isblank (p[5])) && !strncmp (p, "endef", 5))
  824.     {
  825.       p += 5;
  826.       remove_comments (p);
  827.       if (*next_token (p) != '\0')
  828.         makefile_error (filename, lineno,
  829.                 "Extraneous text after `endef' directive");
  830.       /* Define the variable.  */
  831.       if (idx == 0)
  832.         definition[0] = '\0';
  833.       else
  834.         definition[idx - 1] = '\0';
  835.       (void) define_variable (var, strlen (var), definition, origin, 1);
  836.       free (definition);
  837.       freebuffer (&lb);
  838.       return lineno;
  839.     }
  840.       else
  841.     {
  842.       unsigned int len = strlen (lb.buffer);
  843.  
  844.       /* Increase the buffer size if necessary.  */
  845.       if (idx + len + 1 > length)
  846.         {
  847.           length = (idx + len) * 2;
  848.           definition = (char *) xrealloc (definition, length + 1);
  849.         }
  850.  
  851.       bcopy (lb.buffer, &definition[idx], len);
  852.       idx += len;
  853.       /* Separate lines with a newline.  */
  854.       definition[idx++] = '\n';
  855.     }
  856.     }
  857.  
  858.   /* No `endef'!!  */
  859.   makefile_fatal (filename, lineno, "missing `endef', unterminated `define'");
  860.  
  861.   /* NOTREACHED */
  862.   return 0;
  863. }
  864.  
  865. /* Interpret conditional commands "ifdef", "ifndef", "ifeq",
  866.    "ifneq", "else" and "endif".
  867.    LINE is the input line, with the command as its first word.
  868.  
  869.    FILENAME and LINENO are the filename and line number in the
  870.    current makefile.  They are used for error messages.
  871.  
  872.    Value is -1 if the line is invalid,
  873.    0 if following text should be interpreted,
  874.    1 if following text should be ignored.  */
  875.  
  876. static int
  877. conditional_line (line, filename, lineno)
  878.      char *line;
  879.      char *filename;
  880.      unsigned int lineno;
  881. {
  882.   int notdef;
  883.   char *cmdname;
  884.   register unsigned int i;
  885.  
  886.   if (*line == 'i')
  887.     {
  888.       /* It's an "if..." command.  */
  889.       notdef = line[2] == 'n';
  890.       if (notdef)
  891.     {
  892.       cmdname = line[3] == 'd' ? "ifndef" : "ifneq";
  893.       line += cmdname[3] == 'd' ? 7 : 6;
  894.     }
  895.       else
  896.     {
  897.       cmdname = line[2] == 'd' ? "ifdef" : "ifeq";
  898.       line += cmdname[2] == 'd' ? 6 : 5;
  899.     }
  900.     }
  901.   else
  902.     {
  903.       /* It's an "else" or "endif" command.  */
  904.       notdef = line[1] == 'n';
  905.       cmdname = notdef ? "endif" : "else";
  906.       line += notdef ? 5 : 4;
  907.     }
  908.  
  909.   line = next_token (line);
  910.  
  911.   if (*cmdname == 'e')
  912.     {
  913.       if (*line != '\0')
  914.     makefile_error (filename, lineno,
  915.             "Extraneous text after `%s' directive",
  916.             cmdname);
  917.       /* "Else" or "endif".  */
  918.       if (conditionals->if_cmds == 0)
  919.     makefile_fatal (filename, lineno, "extraneous `%s'", cmdname);
  920.       /* NOTDEF indicates an `endif' command.  */
  921.       if (notdef)
  922.     --conditionals->if_cmds;
  923.       else if (conditionals->seen_else[conditionals->if_cmds - 1])
  924.     makefile_fatal (filename, lineno, "only one `else' per conditional");
  925.       else
  926.     {
  927.       /* Toggle the state of ignorance.  */
  928.       conditionals->ignoring[conditionals->if_cmds - 1]
  929.         = !conditionals->ignoring[conditionals->if_cmds - 1];
  930.       /* Record that we have seen an `else' in this conditional.
  931.          A second `else' will be erroneous.  */
  932.       conditionals->seen_else[conditionals->if_cmds - 1] = 1;
  933.     }
  934.       for (i = 0; i < conditionals->if_cmds; ++i)
  935.     if (conditionals->ignoring[i])
  936.       return 1;
  937.       return 0;
  938.     }
  939.  
  940.   if (conditionals->allocated == 0)
  941.     {
  942.       conditionals->allocated = 5;
  943.       conditionals->ignoring = (char *) xmalloc (conditionals->allocated);
  944.       conditionals->seen_else = (char *) xmalloc (conditionals->allocated);
  945.     }
  946.  
  947.   ++conditionals->if_cmds;
  948.   if (conditionals->if_cmds > conditionals->allocated)
  949.     {
  950.       conditionals->allocated += 5;
  951.       conditionals->ignoring = (char *)
  952.     xrealloc (conditionals->ignoring, conditionals->allocated);
  953.       conditionals->seen_else = (char *)
  954.     xrealloc (conditionals->seen_else, conditionals->allocated);
  955.     }
  956.  
  957.   /* Record that we have seen an `if...' but no `else' so far.  */
  958.   conditionals->seen_else[conditionals->if_cmds - 1] = 0;
  959.  
  960.   /* Search through the stack to see if we're already ignoring.  */
  961.   for (i = 0; i < conditionals->if_cmds - 1; ++i)
  962.     if (conditionals->ignoring[i])
  963.       {
  964.     /* We are already ignoring, so just push a level
  965.        to match the next "else" or "endif", and keep ignoring.
  966.        We don't want to expand variables in the condition.  */
  967.     conditionals->ignoring[conditionals->if_cmds - 1] = 1;
  968.     return 1;
  969.       }
  970.  
  971.   if (cmdname[notdef ? 3 : 2] == 'd')
  972.     {
  973.       /* "Ifdef" or "ifndef".  */
  974.       struct variable *v;
  975.       register char *p = end_of_token (line);
  976.       i = p - line;
  977.       p = next_token (p);
  978.       if (*p != '\0')
  979.     return -1;
  980.       v = lookup_variable (line, i);
  981.       conditionals->ignoring[conditionals->if_cmds - 1]
  982.     = (v != 0 && *v->value != '\0') == notdef;
  983.     }
  984.   else
  985.     {
  986.       /* "Ifeq" or "ifneq".  */
  987.       char *s1, *s2;
  988.       unsigned int len;
  989.       char termin = *line == '(' ? ',' : *line;
  990.  
  991.       if (termin != ',' && termin != '"' && termin != '\'')
  992.     return -1;
  993.  
  994.       s1 = ++line;
  995.       /* Find the end of the first string.  */
  996.       if (termin == ',')
  997.     {
  998.       register int count = 0;
  999.       for (; *line != '\0'; ++line)
  1000.         if (*line == '(')
  1001.           ++count;
  1002.         else if (*line == ')')
  1003.           --count;
  1004.         else if (*line == ',' && count <= 0)
  1005.           break;
  1006.     }
  1007.       else
  1008.     while (*line != '\0' && *line != termin)
  1009.       ++line;
  1010.  
  1011.       if (*line == '\0')
  1012.     return -1;
  1013.  
  1014.       *line++ = '\0';
  1015.  
  1016.       s2 = variable_expand (s1);
  1017.       /* We must allocate a new copy of the expanded string because
  1018.      variable_expand re-uses the same buffer.  */
  1019.       len = strlen (s2);
  1020.       s1 = (char *) alloca (len + 1);
  1021.       bcopy (s2, s1, len + 1);
  1022.  
  1023.       if (termin != ',')
  1024.     /* Find the start of the second string.  */
  1025.     line = next_token (line);
  1026.  
  1027.       termin = termin == ',' ? ')' : *line;
  1028.       if (termin != ')' && termin != '"' && termin != '\'')
  1029.     return -1;
  1030.  
  1031.       /* Find the end of the second string.  */
  1032.       if (termin == ')')
  1033.     {
  1034.       register int count = 0;
  1035.       s2 = next_token (line);
  1036.       for (line = s2; *line != '\0'; ++line)
  1037.         {
  1038.           if (*line == '(')
  1039.         ++count;
  1040.           else if (*line == ')')
  1041.         if (count <= 0)
  1042.           break;
  1043.         else
  1044.           --count;
  1045.         }
  1046.     }
  1047.       else
  1048.     {
  1049.       ++line;
  1050.       s2 = line;
  1051.       while (*line != '\0' && *line != termin)
  1052.         ++line;
  1053.     }
  1054.  
  1055.       if (*line == '\0')
  1056.     return -1;
  1057.  
  1058.       *line = '\0';
  1059.       line = next_token (++line);
  1060.       if (*line != '\0')
  1061.     makefile_error (filename, lineno,
  1062.             "Extraneous text after `%s' directive",
  1063.             cmdname);
  1064.  
  1065.       s2 = variable_expand (s2);
  1066.       conditionals->ignoring[conditionals->if_cmds - 1]
  1067.     = streq (s1, s2) == notdef;
  1068.     }
  1069.  
  1070.   /* Search through the stack to see if we're ignoring.  */
  1071.   for (i = 0; i < conditionals->if_cmds; ++i)
  1072.     if (conditionals->ignoring[i])
  1073.       return 1;
  1074.   return 0;
  1075. }
  1076.  
  1077. /* Remove duplicate dependencies in CHAIN.  */
  1078.  
  1079. void
  1080. uniquize_deps (chain)
  1081.      struct dep *chain;
  1082. {
  1083.   register struct dep *d;
  1084.  
  1085.   /* Make sure that no dependencies are repeated.  This does not
  1086.      really matter for the purpose of updating targets, but it
  1087.      might make some names be listed twice for $^ and $?.  */
  1088.  
  1089.   for (d = chain; d != 0; d = d->next)
  1090.     {
  1091.       struct dep *last, *next;
  1092.  
  1093.       last = d;
  1094.       next = d->next;
  1095.       while (next != 0)
  1096.     if (streq (dep_name (d), dep_name (next)))
  1097.       {
  1098.         struct dep *n = next->next;
  1099.         last->next = n;
  1100.         if (next->name != 0 && next->name != d->name)
  1101.           free (next->name);
  1102.         if (next != d)
  1103.           free ((char *) next);
  1104.         next = n;
  1105.       }
  1106.     else
  1107.       {
  1108.         last = next;
  1109.         next = next->next;
  1110.       }
  1111.     }
  1112. }
  1113.  
  1114. /* Record a description line for files FILENAMES,
  1115.    with dependencies DEPS, commands to execute described
  1116.    by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
  1117.    TWO_COLON is nonzero if a double colon was used.
  1118.    If not nil, PATTERN is the `%' pattern to make this
  1119.    a static pattern rule, and PATTERN_PERCENT is a pointer
  1120.    to the `%' within it.
  1121.  
  1122.    The links of FILENAMES are freed, and so are any names in it
  1123.    that are not incorporated into other data structures.  */
  1124.  
  1125. static void
  1126. record_files (filenames, pattern, pattern_percent, deps, commands_started,
  1127.           commands, commands_idx, two_colon, filename, lineno, set_default)
  1128.      struct nameseq *filenames;
  1129.      char *pattern, *pattern_percent;
  1130.      struct dep *deps;
  1131.      unsigned int commands_started;
  1132.      char *commands;
  1133.      unsigned int commands_idx;
  1134.      int two_colon;
  1135.      char *filename;
  1136.      unsigned int lineno;
  1137.      int set_default;
  1138. {
  1139.   struct nameseq *nextf;
  1140.   int implicit = 0;
  1141.   unsigned int max_targets, target_idx;
  1142.   char **targets = 0, **target_percents = 0;
  1143.   struct commands *cmds;
  1144.  
  1145.   if (commands_idx > 0)
  1146.     {
  1147.       cmds = (struct commands *) xmalloc (sizeof (struct commands));
  1148.       cmds->filename = filename;
  1149.       cmds->lineno = commands_started;
  1150.       cmds->commands = savestring (commands, commands_idx);
  1151.       cmds->command_lines = 0;
  1152.     }
  1153.   else
  1154.     cmds = 0;
  1155.  
  1156.   for (; filenames != 0; filenames = nextf)
  1157.     {
  1158.       register char *name = filenames->name;
  1159.       register struct file *f;
  1160.       register struct dep *d;
  1161.       struct dep *this;
  1162.       char *implicit_percent;
  1163.  
  1164.       nextf = filenames->next;
  1165.       free ((char *) filenames);
  1166.  
  1167.       implicit_percent = find_percent (name);
  1168.       implicit |= implicit_percent != 0;
  1169.  
  1170.       if (implicit && pattern != 0)
  1171.     makefile_fatal (filename, lineno,
  1172.             "mixed implicit and static pattern rules");
  1173.  
  1174.       if (implicit && implicit_percent == 0)
  1175.     makefile_fatal (filename, lineno, "mixed implicit and normal rules");
  1176.  
  1177.       if (implicit)
  1178.     {
  1179.       if (targets == 0)
  1180.         {
  1181.           max_targets = 5;
  1182.           targets = (char **) xmalloc (5 * sizeof (char *));
  1183.           target_percents = (char **) xmalloc (5 * sizeof (char *));
  1184.           target_idx = 0;
  1185.         }
  1186.       else if (target_idx == max_targets - 1)
  1187.         {
  1188.           max_targets += 5;
  1189.           targets = (char **) xrealloc ((char *) targets,
  1190.                         max_targets * sizeof (char *));
  1191.           target_percents
  1192.         = (char **) xrealloc ((char *) target_percents,
  1193.                       max_targets * sizeof (char *));
  1194.         }
  1195.       targets[target_idx] = name;
  1196.       target_percents[target_idx] = implicit_percent;
  1197.       ++target_idx;
  1198.       continue;
  1199.     }
  1200.  
  1201.       /* If there are multiple filenames, copy the chain DEPS
  1202.      for all but the last one.  It is not safe for the same deps
  1203.      to go in more than one place in the data base.  */
  1204.       this = nextf != 0 ? copy_dep_chain (deps) : deps;
  1205.  
  1206.       if (pattern != 0)
  1207.     /* If this is an extended static rule:
  1208.        `targets: target%pattern: dep%pattern; cmds',
  1209.        translate each dependency pattern into a plain filename
  1210.        using the target pattern and this target's name.  */
  1211.     if (!pattern_matches (pattern, pattern_percent, name))
  1212.       {
  1213.         /* Give a warning if the rule is meaningless.  */
  1214.         makefile_error (filename, lineno,
  1215.                 "target `%s' doesn't match the target pattern",
  1216.                 name);
  1217.         this = 0;
  1218.       }
  1219.     else
  1220.       {
  1221.         /* We use patsubst_expand to do the work of translating
  1222.            the target pattern, the target's name and the dependencies'
  1223.            patterns into plain dependency names.  */
  1224.         char *buffer = variable_expand ("");
  1225.  
  1226.         for (d = this; d != 0; d = d->next)
  1227.           {
  1228.         char *o;
  1229.         char *percent = find_percent (d->name);
  1230.         if (percent == 0)
  1231.           continue;
  1232.         o = patsubst_expand (buffer, name, pattern, d->name,
  1233.                      pattern_percent, percent);
  1234.         free (d->name);
  1235.         d->name = savestring (buffer, o - buffer);
  1236. #ifdef __EMX__
  1237.         if (d->name[0] != '.')
  1238.           _fnlwr(d->name);
  1239. #endif
  1240.           }
  1241.       }
  1242.       
  1243.       if (!two_colon)
  1244.     {
  1245.       /* Single-colon.  Combine these dependencies
  1246.          with others in file's existing record, if any.  */
  1247.       f = enter_file (name);
  1248.  
  1249.       if (f->double_colon)
  1250.         makefile_fatal (filename, lineno,
  1251.                 "target file `%s' has both : and :: entries",
  1252.                 f->name);
  1253.  
  1254.       /* If CMDS == F->CMDS, this target was listed in this rule
  1255.          more than once.  Just give a warning since this is harmless.  */
  1256.       if (cmds != 0 && cmds == f->cmds)
  1257.         makefile_error
  1258.           (filename, lineno,
  1259.            "target `%s' given more than once in the same rule.",
  1260.            f->name);
  1261.  
  1262.       /* Check for two single-colon entries both with commands.
  1263.          Check is_target so that we don't lose on files such as .c.o
  1264.          whose commands were preinitialized.  */
  1265.       else if (cmds != 0 && f->cmds != 0 && f->is_target)
  1266.         {
  1267.           makefile_error (cmds->filename, cmds->lineno,
  1268.                   "warning: overriding commands for target `%s'",
  1269.                   f->name);
  1270.           makefile_error (f->cmds->filename, f->cmds->lineno,
  1271.                   "warning: ignoring old commands for target `%s'",
  1272.                   f->name);
  1273.         }
  1274.  
  1275.       f->is_target = 1;
  1276.  
  1277.       /* Defining .DEFAULT with no deps or cmds clears it.  */
  1278.       if (f == default_file && this == 0 && cmds == 0)
  1279.         f->cmds = 0;
  1280.       if (cmds != 0)
  1281.         f->cmds = cmds;
  1282.       /* Defining .SUFFIXES with no dependencies
  1283.          clears out the list of suffixes.  */
  1284.       if (f == suffix_file && this == 0)
  1285.         {
  1286.           d = f->deps;
  1287.           while (d != 0)
  1288.         {
  1289.           struct dep *nextd = d->next;
  1290.            free (d->name);
  1291.            free (d);
  1292.           d = nextd;
  1293.         }
  1294.           f->deps = 0;
  1295.         }
  1296.       else if (f->deps != 0)
  1297.         {
  1298.           /* Add the file's old deps and the new ones in THIS together.  */
  1299.  
  1300.           struct dep *firstdeps, *moredeps;
  1301.           if (cmds != 0)
  1302.         {
  1303.           /* This is the rule with commands, so put its deps first.
  1304.              The rationale behind this is that $< expands to the
  1305.              first dep in the chain, and commands use $< expecting
  1306.              to get the dep that rule specifies.  */
  1307.           firstdeps = this;
  1308.           moredeps = f->deps;
  1309.         }
  1310.           else
  1311.         {
  1312.           /* Append the new deps to the old ones.  */
  1313.           firstdeps = f->deps;
  1314.           moredeps = this;
  1315.         }
  1316.  
  1317.           if (firstdeps == 0)
  1318.         firstdeps = moredeps;
  1319.           else
  1320.         {
  1321.           d = firstdeps;
  1322.           while (d->next != 0)
  1323.             d = d->next;
  1324.           d->next = moredeps;
  1325.         }
  1326.  
  1327.           f->deps = firstdeps;
  1328.         }
  1329.       else
  1330.         f->deps = this;
  1331.  
  1332.       /* If this is a static pattern rule, set the file's stem to
  1333.          the part of its name that matched the `%' in the pattern,
  1334.          so you can use $* in the commands.  */
  1335.       if (pattern != 0)
  1336.         {
  1337.           static char *percent = "%";
  1338.           char *buffer = variable_expand ("");
  1339.           char *o = patsubst_expand (buffer, name, pattern, percent,
  1340.                      pattern_percent, percent);
  1341.           f->stem = savestring (buffer, o - buffer);
  1342.         }
  1343.     }
  1344.       else
  1345.     {
  1346.       /* Double-colon.  Make a new record
  1347.          even if the file already has one.  */
  1348.       f = lookup_file (name);
  1349.       /* Check for both : and :: rules.  Check is_target so
  1350.          we don't lose on default suffix rules or makefiles.  */
  1351.       if (f != 0 && f->is_target && !f->double_colon)
  1352.         makefile_fatal (filename, lineno,
  1353.                 "target file `%s' has both : and :: entries",
  1354.                 f->name);
  1355.       f = enter_file (name);
  1356.       /* If there was an existing entry and it was a double-colon
  1357.          entry, enter_file will have returned a new one, making it the
  1358.          prev pointer of the old one, and setting its double_colon
  1359.          pointer to the first one.  */
  1360.       if (f->double_colon == 0)
  1361.         /* This is the first entry for this name, so we must
  1362.            set its double_colon pointer to itself.  */
  1363.         f->double_colon = f;
  1364.       f->is_target = 1;
  1365.       f->deps = this;
  1366.       f->cmds = cmds;
  1367.     }
  1368.  
  1369.       /* Free name if not needed further.  */
  1370.       if (f != 0 && name != f->name
  1371.       && (name < f->name || name > f->name + strlen (f->name)))
  1372.     {
  1373.       free (name);
  1374.       name = f->name;
  1375.     }
  1376.  
  1377.       /* See if this is first target seen whose name does
  1378.      not start with a `.', unless it contains a slash.  */
  1379.       if (default_goal_file == 0 && set_default
  1380.       && (*name != '.' || index (name, '/') != 0))
  1381.     {
  1382.       int reject = 0;
  1383.  
  1384.       /* If this file is a suffix, don't
  1385.          let it be the default goal file.  */
  1386.  
  1387.       for (d = suffix_file->deps; d != 0; d = d->next)
  1388.         {
  1389.           register struct dep *d2;
  1390.           if (*dep_name (d) != '.' && streq (name, dep_name (d)))
  1391.         {
  1392.           reject = 1;
  1393.           break;
  1394.         }
  1395.           for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
  1396.         {
  1397.           register unsigned int len = strlen (dep_name (d2));
  1398.           if (strncmp (name, dep_name (d2), len))
  1399.             continue;
  1400.           if (streq (name + len, dep_name (d)))
  1401.             {
  1402.               reject = 1;
  1403.               break;
  1404.             }
  1405.         }
  1406.           if (reject)
  1407.         break;
  1408.         }
  1409.  
  1410.       if (!reject)
  1411.         default_goal_file = f;
  1412.     }
  1413.     }
  1414.  
  1415.   if (implicit)
  1416.     {
  1417.       targets[target_idx] = 0;
  1418.       target_percents[target_idx] = 0;
  1419.       create_pattern_rule (targets, target_percents, two_colon, deps, cmds, 1);
  1420.       free ((char *) target_percents);
  1421.     }
  1422. }
  1423.  
  1424. /* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
  1425.    Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
  1426.    Quoting backslashes are removed from STRING by compacting it into
  1427.    itself.  Returns a pointer to the first unquoted STOPCHAR if there is
  1428.    one, or nil if there are none.  */
  1429.  
  1430. char *
  1431. find_char_unquote (string, stopchar, blank)
  1432.      char *string;
  1433.      int stopchar;
  1434.      int blank;
  1435. {
  1436.   unsigned int string_len = strlen (string);
  1437.   register char *p = string;
  1438.  
  1439.   while (1)
  1440.     {
  1441.       if (blank)
  1442.     {
  1443. #ifdef __EMX__
  1444.       while (*p != '\0' && !isblank (*p))
  1445.         if (*p == stopchar && (stopchar != ':' || isblank(p[1]) || 
  1446.                    p[1] == 0 || p[1] == ':' || p[1] == ';'))
  1447.           break;
  1448.         else
  1449.           ++p;
  1450. #else
  1451.       while (*p != '\0' && *p != stopchar && !isblank (*p))
  1452.         ++p;
  1453. #endif
  1454.       if (*p == '\0')
  1455.         break;
  1456.     }
  1457.       else
  1458.     {
  1459.       p = index (p, stopchar);
  1460.       if (p == 0)
  1461.         break;
  1462.     }
  1463.       if (p > string && p[-1] == '\\')
  1464.     {
  1465.       /* Search for more backslashes.  */
  1466.       register int i = -2;
  1467.       while (&p[i] >= string && p[i] == '\\')
  1468.         --i;
  1469.       ++i;
  1470.       /* The number of backslashes is now -I.
  1471.          Copy P over itself to swallow half of them.  */
  1472.       bcopy (&p[i / 2], &p[i], (string_len - (p - string)) - (i / 2) + 1);
  1473.       p += i / 2;
  1474.       if (i % 2 == 0)
  1475.         /* All the backslashes quoted each other; the STOPCHAR was
  1476.            unquoted.  */
  1477.         return p;
  1478.  
  1479.       /* The STOPCHAR was quoted by a backslash.  Look for another.  */
  1480.     }
  1481.       else
  1482.     /* No backslash in sight.  */
  1483.     return p;
  1484.     }
  1485.  
  1486.   /* Never hit a STOPCHAR or blank (with BLANK nonzero).  */
  1487.   return 0;
  1488. }
  1489.  
  1490. /* Search PATTERN for an unquoted %.  */
  1491.  
  1492. char *
  1493. find_percent (pattern)
  1494.      char *pattern;
  1495. {
  1496.   return find_char_unquote (pattern, '%', 0);
  1497. }
  1498.  
  1499. /* Search STRING for an unquoted ; that is not after an unquoted #.  */
  1500.  
  1501. static char *
  1502. find_semicolon (string)
  1503.      char *string;
  1504. {
  1505.   return (find_char_unquote (string, '#', 0) == 0
  1506.       ? find_char_unquote (string, ';', 0) : 0);
  1507. }
  1508.  
  1509. /* Parse a string into a sequence of filenames represented as a
  1510.    chain of struct nameseq's in reverse order and return that chain.
  1511.  
  1512.    The string is passed as STRINGP, the address of a string pointer.
  1513.    The string pointer is updated to point at the first character
  1514.    not parsed, which either is a null char or equals STOPCHAR.
  1515.  
  1516.    SIZE is how big to construct chain elements.
  1517.    This is useful if we want them actually to be other structures
  1518.    that have room for additional info.
  1519.  
  1520.    If STRIP is nonzero, strip `./'s off the beginning.  */
  1521.  
  1522. struct nameseq *
  1523. parse_file_seq (stringp, stopchar, size, strip)
  1524.      char **stringp;
  1525.      char stopchar;
  1526.      unsigned int size;
  1527.      int strip;
  1528. {
  1529.   register struct nameseq *new = 0;
  1530.   register struct nameseq *new1, *lastnew1;
  1531.   register char *p = *stringp;
  1532.   char *q;
  1533.   char *name;
  1534.  
  1535.   while (1)
  1536.     {
  1537.       /* Skip whitespace; see if any more names are left.  */
  1538.       p = next_token (p);
  1539.       if (*p == '\0')
  1540.     break;
  1541.       if (*p == stopchar)
  1542.     break;
  1543.       /* Yes, find end of next name.  */
  1544.       q = p;
  1545.       p = find_char_unquote (q, stopchar, 1);
  1546.       if (p == 0)
  1547.     p = q + strlen (q);
  1548.  
  1549.       if (strip)
  1550.     /* Skip leading `./'s.  */
  1551.     while (p - q > 2 && q[0] == '.' && q[1] == '/')
  1552.       {
  1553.         q += 2;        /* Skip "./".  */
  1554.         while (q < p && *q == '/')
  1555.           /* Skip following slashes: ".//foo" is "foo", not "/foo".  */
  1556.           ++q;
  1557.       }
  1558.  
  1559.       /* Extract the filename just found, and skip it.  */
  1560.  
  1561.       if (q == p)
  1562.     /* ".///" was stripped to "".  */
  1563.     name = savestring ("./", 2);
  1564.       else
  1565.     name = savestring (q, p - q);
  1566.  
  1567.       /* Add it to the front of the chain.  */
  1568.       new1 = (struct nameseq *) xmalloc (size);
  1569.       new1->name = name;
  1570.       new1->next = new;
  1571.       new = new1;
  1572.     }
  1573.  
  1574. #ifndef NO_ARCHIVES
  1575.  
  1576.   /* Look for multi-word archive references.
  1577.      They are indicated by a elt ending with an unmatched `)' and
  1578.      an elt further down the chain (i.e., previous in the file list)
  1579.      with an unmatched `(' (e.g., "lib(mem").  */
  1580.  
  1581.   for (new1 = new, lastnew1 = 0; new1 != 0; lastnew1 = new1, new1 = new1->next)
  1582.     if (new1->name[0] != '('    /* Don't catch "(%)" and suchlike.  */
  1583.     && new1->name[strlen (new1->name) - 1] == ')'
  1584.     && index (new1->name, '(') == 0)
  1585.       {
  1586.     /* NEW1 ends with a `)' but does not contain a `('.
  1587.        Look back for an elt with an opening `(' but no closing `)'.  */
  1588.  
  1589.     struct nameseq *n = new1->next, *lastn = new1;
  1590.     char *paren;
  1591.     while (n != 0 && (paren = index (n->name, '(')) == 0)
  1592.       {
  1593.         lastn = n;
  1594.         n = n->next;
  1595.       }
  1596.     if (n != 0
  1597.         /* Ignore something starting with `(', as that cannot actually
  1598.            be an archive-member reference (and treating it as such
  1599.            results in an empty file name, which causes much lossage).  */
  1600.         && n->name[0] != '(')
  1601.       {
  1602.         /* N is the first element in the archive group.
  1603.            Its name looks like "lib(mem" (with no closing `)').  */
  1604.  
  1605.         char *libname;
  1606.  
  1607.         /* Copy "lib(" into LIBNAME.  */
  1608.         ++paren;
  1609.         libname = (char *) alloca (paren - n->name + 1);
  1610.         bcopy (n->name, libname, paren - n->name);
  1611.         libname[paren - n->name] = '\0';
  1612.  
  1613.         if (*paren == '\0')
  1614.           {
  1615.         /* N was just "lib(", part of something like "lib( a b)".
  1616.            Edit it out of the chain and free its storage.  */
  1617.         lastn->next = n->next;
  1618.         free (n->name);
  1619.         free ((char *) n);
  1620.         /* LASTN->next is the new stopping elt for the loop below.  */
  1621.         n = lastn->next;
  1622.           }
  1623.         else
  1624.           {
  1625.         /* Replace N's name with the full archive reference.  */
  1626.         name = concat (libname, paren, ")");
  1627.         free (n->name);
  1628.         n->name = name;
  1629.           }
  1630.  
  1631.         if (new1->name[1] == '\0')
  1632.           {
  1633.         /* NEW1 is just ")", part of something like "lib(a b )".
  1634.            Omit it from the chain and free its storage.  */
  1635.         if (lastnew1 == 0)
  1636.           new = new1->next;
  1637.         else
  1638.           lastnew1->next = new1->next;
  1639.         lastn = new1;
  1640.         new1 = new1->next;
  1641.         free (lastn->name);
  1642.         free ((char *) lastn);
  1643.           }
  1644.         else
  1645.           {
  1646.         /* Replace also NEW1->name, which already has closing `)'.  */
  1647.         name = concat (libname, new1->name, "");
  1648.         free (new1->name);
  1649.         new1->name = name;
  1650.         new1 = new1->next;
  1651.           }
  1652.  
  1653.         /* Trace back from NEW1 (the end of the list) until N
  1654.            (the beginning of the list), rewriting each name
  1655.            with the full archive reference.  */
  1656.         
  1657.         while (new1 != n)
  1658.           {
  1659.         name = concat (libname, new1->name, ")");
  1660.         free (new1->name);
  1661.         new1->name = name;
  1662.         new1 = new1->next;
  1663.           }
  1664.  
  1665.         if (new1 == 0)
  1666.           /* We might have slurped up the whole list,
  1667.          and continuing the loop would dereference NEW1.  */
  1668.           break;
  1669.       }
  1670.       }
  1671.  
  1672. #endif
  1673.  
  1674.   *stringp = p;
  1675.   return new;
  1676. }
  1677.  
  1678. /* Read a line of text from STREAM into LINEBUFFER.
  1679.    Combine continuation lines into one line.
  1680.    Return the number of actual lines read (> 1 if hacked continuation lines).
  1681.  */
  1682.  
  1683. static unsigned int
  1684. readline (linebuffer, stream, filename, lineno)
  1685.      struct linebuffer *linebuffer;
  1686.      FILE *stream;
  1687.      char *filename;
  1688.      unsigned int lineno;
  1689. {
  1690.   char *buffer = linebuffer->buffer;
  1691.   register char *p = linebuffer->buffer;
  1692.   register char *end = p + linebuffer->size;
  1693.   register int len, lastlen = 0;
  1694.   register char *p2;
  1695.   register unsigned int nlines = 0;
  1696.   register int backslash;
  1697.  
  1698.   *p = '\0';
  1699.  
  1700.   while (fgets (p, end - p, stream) != 0)
  1701.     {
  1702.       len = strlen (p);
  1703.       if (len == 0)
  1704.     {
  1705.       /* This only happens when the first thing on the line is a '\0'.
  1706.          It is a pretty hopeless case, but (wonder of wonders) Athena
  1707.          lossage strikes again!  (xmkmf puts NULs in its makefiles.)
  1708.          There is nothing really to be done; we synthesize a newline so
  1709.          the following line doesn't appear to be part of this line.  */
  1710.       makefile_error (filename, lineno,
  1711.               "warning: NUL character seen; rest of line ignored");
  1712.       p[0] = '\n';
  1713.       len = 1;
  1714.     }
  1715.  
  1716.       p += len;
  1717.       if (p[-1] != '\n')
  1718.     {
  1719.       /* Probably ran out of buffer space.  */
  1720.       register unsigned int p_off = p - buffer;
  1721.       linebuffer->size *= 2;
  1722.       buffer = (char *) xrealloc (buffer, linebuffer->size);
  1723.       p = buffer + p_off;
  1724.       end = buffer + linebuffer->size;
  1725.       linebuffer->buffer = buffer;
  1726.       *p = '\0';
  1727.       lastlen = len;
  1728.       continue;
  1729.     }
  1730.  
  1731.       ++nlines;
  1732.  
  1733.       if (len == 1 && p > buffer)
  1734.     /* P is pointing at a newline and it's the beginning of
  1735.        the buffer returned by the last fgets call.  However,
  1736.        it is not necessarily the beginning of a line if P is
  1737.        pointing past the beginning of the holding buffer.
  1738.        If the buffer was just enlarged (right before the newline),
  1739.        we must account for that, so we pretend that the two lines
  1740.        were one line.  */
  1741.     len += lastlen;
  1742.       lastlen = len;
  1743.       backslash = 0;
  1744.       for (p2 = p - 2; --len > 0; --p2)
  1745.     {
  1746.       if (*p2 == '\\')
  1747.         backslash = !backslash;
  1748.       else
  1749.         break;
  1750.     }
  1751.       
  1752.       if (!backslash)
  1753.     {
  1754.       p[-1] = '\0';
  1755.       if (p - p2 > 2)
  1756.         p[-2] = '\0'; /* kill one of multiple backslashes */
  1757.       break;
  1758.     }
  1759.  
  1760.       if (end - p <= 1)
  1761.     {
  1762.       /* Enlarge the buffer.  */
  1763.       register unsigned int p_off = p - buffer;
  1764.       linebuffer->size *= 2;
  1765.       buffer = (char *) xrealloc (buffer, linebuffer->size);
  1766.       p = buffer + p_off;
  1767.       end = buffer + linebuffer->size;
  1768.       linebuffer->buffer = buffer;
  1769.     }
  1770.     }
  1771.  
  1772.   if (ferror (stream))
  1773.     pfatal_with_name (filename);
  1774.  
  1775.   return nlines;
  1776. }
  1777.  
  1778. /* Construct the list of include directories
  1779.    from the arguments and the default list.  */
  1780.  
  1781. void
  1782. construct_include_path (arg_dirs)
  1783.      char **arg_dirs;
  1784. {
  1785.   register unsigned int i;
  1786.   struct stat stbuf;
  1787.  
  1788.   /* Table to hold the dirs.  */
  1789.  
  1790.   register unsigned int defsize = (sizeof (default_include_directories)
  1791.                    / sizeof (default_include_directories[0]));
  1792.   register unsigned int max = 5;
  1793.   register char **dirs = (char **) xmalloc ((5 + defsize) * sizeof (char *));
  1794.   register unsigned int idx = 0;
  1795.  
  1796.   /* First consider any dirs specified with -I switches.
  1797.      Ignore dirs that don't exist.  */
  1798.  
  1799.   if (arg_dirs != 0)
  1800.     while (*arg_dirs != 0)
  1801.       {
  1802.     char *dir = *arg_dirs++;
  1803.  
  1804.     if (dir[0] == '~')
  1805.       {
  1806.         char *expanded = tilde_expand (dir);
  1807.         if (expanded != 0)
  1808.           dir = expanded;
  1809.       }
  1810.  
  1811.     if (stat (dir, &stbuf) == 0 && S_ISDIR (stbuf.st_mode))
  1812.       {
  1813.         if (idx == max - 1)
  1814.           {
  1815.         max += 5;
  1816.         dirs = (char **)
  1817.           xrealloc ((char *) dirs, (max + defsize) * sizeof (char *));
  1818.           }
  1819.         dirs[idx++] = dir;
  1820.       }
  1821.     else if (dir != arg_dirs[-1])
  1822.       free (dir);
  1823.       }
  1824.  
  1825.   /* Now add at the end the standard default dirs.  */
  1826.  
  1827.   for (i = 0; default_include_directories[i] != 0; ++i)
  1828.     if (stat (default_include_directories[i], &stbuf) == 0
  1829.     && S_ISDIR (stbuf.st_mode))
  1830.       dirs[idx++] = default_include_directories[i];
  1831.  
  1832.   dirs[idx] = 0;
  1833.  
  1834.   /* Now compute the maximum length of any name in it.  */
  1835.  
  1836.   max_incl_len = 0;
  1837.   for (i = 0; i < idx; ++i)
  1838.     {
  1839.       unsigned int len = strlen (dirs[i]);
  1840.       /* If dir name is written with a trailing slash, discard it.  */
  1841.       if (dirs[i][len - 1] == '/')
  1842.     /* We can't just clobber a null in because it may have come from
  1843.        a literal string and literal strings may not be writable.  */
  1844.     dirs[i] = savestring (dirs[i], len - 1);
  1845.       if (len > max_incl_len)
  1846.     max_incl_len = len;
  1847.     }
  1848.  
  1849.   include_directories = dirs;
  1850. }
  1851.  
  1852. /* Expand ~ or ~USER at the beginning of NAME.
  1853.    Return a newly malloc'd string or 0.  */
  1854.  
  1855. char *
  1856. tilde_expand (name)
  1857.      char *name;
  1858. {
  1859.   if (name[1] == '/' || name[1] == '\0')
  1860.     {
  1861.       extern char *getenv ();
  1862.       char *home_dir;
  1863.       int is_variable;
  1864.  
  1865.       {
  1866.     /* Turn off --warn-undefined-variables while we expand HOME.  */
  1867.     int save = warn_undefined_variables_flag;
  1868.     warn_undefined_variables_flag = 0;
  1869.  
  1870.     home_dir = allocated_variable_expand ("$(HOME)");
  1871.  
  1872.     warn_undefined_variables_flag = save;
  1873.       }
  1874.   
  1875.       is_variable = home_dir[0] != '\0';
  1876.       if (!is_variable)
  1877.     {
  1878.       free (home_dir);
  1879.       home_dir = getenv ("HOME");
  1880.     }
  1881.       if (home_dir == 0 || home_dir[0] == '\0')
  1882.     {
  1883.       extern char *getlogin ();
  1884.       char *name = getlogin ();
  1885.       home_dir = 0;
  1886.       if (name != 0)
  1887.         {
  1888.           struct passwd *p = getpwnam (name);
  1889.           if (p != 0)
  1890.         home_dir = p->pw_dir;
  1891.         }
  1892.     }
  1893.       if (home_dir != 0)
  1894.     {
  1895.       char *new = concat (home_dir, "", name + 1);
  1896.       if (is_variable)
  1897.         free (home_dir);
  1898.       return new;
  1899.     }
  1900.     }
  1901.   else
  1902.     {
  1903.       struct passwd *pwent;
  1904.       char *userend = index (name + 1, '/');
  1905.       if (userend != 0)
  1906.     *userend = '\0';
  1907.       pwent = getpwnam (name + 1);
  1908.       if (pwent != 0)
  1909.     {
  1910.       if (userend == 0)
  1911.         return savestring (pwent->pw_dir, strlen (pwent->pw_dir));
  1912.       else
  1913.         return concat (pwent->pw_dir, "/", userend + 1);
  1914.     }
  1915.       else if (userend != 0)
  1916.     *userend = '/';
  1917.     }
  1918.  
  1919.   return 0;
  1920. }
  1921.  
  1922. /* Given a chain of struct nameseq's describing a sequence of filenames,
  1923.    in reverse of the intended order, return a new chain describing the
  1924.    result of globbing the filenames.  The new chain is in forward order.
  1925.    The links of the old chain are freed or used in the new chain.
  1926.    Likewise for the names in the old chain.
  1927.  
  1928.    SIZE is how big to construct chain elements.
  1929.    This is useful if we want them actually to be other structures
  1930.    that have room for additional info.  */
  1931.  
  1932. struct nameseq *
  1933. multi_glob (chain, size)
  1934.      struct nameseq *chain;
  1935.      unsigned int size;
  1936. {
  1937.   register struct nameseq *new = 0;
  1938.   register struct nameseq *old;
  1939.   struct nameseq *nexto;
  1940.  
  1941.   for (old = chain; old != 0; old = nexto)
  1942.     {
  1943.       glob_t gl;
  1944. #ifndef NO_ARCHIVES
  1945.       char *memname;
  1946. #endif
  1947.  
  1948.       nexto = old->next;
  1949.  
  1950.       if (old->name[0] == '~')
  1951.     {
  1952.       char *newname = tilde_expand (old->name);
  1953.       if (newname != 0)
  1954.         {
  1955.           free (old->name);
  1956.           old->name = newname;
  1957. #ifdef __EMX__
  1958.           if (old->name[0] != '.')
  1959.         _fnlwr(old->name);
  1960. #endif
  1961.         }
  1962.     }
  1963.  
  1964. #ifndef NO_ARCHIVES
  1965.       if (ar_name (old->name))
  1966.     {
  1967.       /* OLD->name is an archive member reference.
  1968.          Replace it with the archive file name,
  1969.          and save the member name in MEMNAME.
  1970.          We will glob on the archive name and then
  1971.          reattach MEMNAME later.  */
  1972.       char *arname;
  1973.       ar_parse_name (old->name, &arname, &memname);
  1974.       free (old->name);
  1975.       old->name = arname;
  1976.     }
  1977.       else
  1978.     memname = 0;
  1979. #endif
  1980.  
  1981.       switch (glob (old->name, GLOB_NOCHECK, NULL, &gl))
  1982.     {
  1983.     case 0:            /* Success.  */
  1984.       {
  1985.         register int i = gl.gl_pathc;
  1986.         while (i-- > 0)
  1987.           {
  1988. #ifndef NO_ARCHIVES
  1989.         if (memname != 0)
  1990.           {
  1991.             /* Try to glob on MEMNAME within the archive.  */
  1992.             struct nameseq *found
  1993.               = ar_glob (gl.gl_pathv[i], memname, size);
  1994.             if (found == 0)
  1995.               {
  1996.             /* No matches.  Use MEMNAME as-is.  */
  1997.             struct nameseq *elt
  1998.               = (struct nameseq *) xmalloc (size);
  1999.             unsigned int alen = strlen (gl.gl_pathv[i]);
  2000.             unsigned int mlen = strlen (memname);
  2001.             elt->name = (char *) xmalloc (alen + 1 + mlen + 2);
  2002.             bcopy (gl.gl_pathv[i], elt->name, alen);
  2003.             elt->name[alen] = '(';
  2004.             bcopy (memname, &elt->name[alen + 1], mlen);
  2005.             elt->name[alen + 1 + mlen] = ')';
  2006.             elt->name[alen + 1 + mlen + 1] = '\0';
  2007.             elt->next = new;
  2008.             new = elt;
  2009.               }
  2010.             else
  2011.               {
  2012.             /* Find the end of the FOUND chain.  */
  2013.             struct nameseq *f = found;
  2014.             while (f->next != 0)
  2015.               f = f->next;
  2016.  
  2017.             /* Attach the chain being built to the end of the FOUND
  2018.                chain, and make FOUND the new NEW chain.  */
  2019.             f->next = new;
  2020.             new = found;
  2021.               }
  2022.  
  2023.             free (memname);
  2024.           }
  2025.         else
  2026. #endif
  2027.           {
  2028.             struct nameseq *elt = (struct nameseq *) xmalloc (size);
  2029.             elt->name = savestring (gl.gl_pathv[i],
  2030.                         strlen (gl.gl_pathv[i]));
  2031. #ifdef __EMX__
  2032.             if (old->name[0] != '.')
  2033.               _fnlwr(elt->name);
  2034. #endif
  2035.             elt->next = new;
  2036.             new = elt;
  2037.           }
  2038.           }
  2039.         globfree (&gl);
  2040.         free (old->name);
  2041.         free (old);
  2042.         break;
  2043.       }
  2044.  
  2045.     case GLOB_NOSPACE:
  2046.       fatal ("virtual memory exhausted");
  2047.       break;
  2048.  
  2049.     default:
  2050.       old->next = new;
  2051.       new = old;
  2052.       break;
  2053.     }
  2054.     }
  2055.  
  2056.   return new;
  2057. }
  2058.